// pages/deleteuser/deleteuser.js
var app = getApp();
var util = require('../../utils/util.js');
Page({
    data: {
        yid: '',
        yname: '',
        ysex: '',
        yowner: '',
        yphone: '',
        yaddress: '',
        createtime: '',
        updatetime: '',
        ynumber: ''
    },
    onLoad: function (options) {
        // 页面初始化 options为页面跳转所带来的参数
        var yid = options.id;
        var page = this;
        wx.request({
            url: 'https://wwl.ycws.cc/ssm/uploadfile/wxselectfile?id=' + yid,
            success: function (res) {
                page.setData({ list: res.data.uploads });
                page.setData({ yid: res.data.uploads.yid });
                page.setData({ yname: res.data.uploads.yname });
                page.setData({ ysex: res.data.uploads.ysex });
                page.setData({ yowner: res.data.uploads.yowner });
                page.setData({ yphone: res.data.uploads.yphone });
                page.setData({ yaddress: res.data.uploads.yaddress });
                page.setData({ createtime: res.data.uploads.createtime });
                page.setData({ updatetime: res.data.uploads.updatetime });
                page.setData({ ynumber: res.data.uploads.ynumber });
                console.log(res.data)
            }
        })
    },
    onReady: function () {
        // 页面渲染完成
    },
    onShow: function () {
        // 页面显示
    },
    onHide: function () {
        // 页面隐藏
    },
    onUnload: function () {
        // 页面关闭
    },
    //进入微信支付
    wxpay: function (orderCode) {
      console.log("app.globalData.openId" + app.globalData.openId);
        var orderCode = util.formatTime(new Date)
        var that = this
        var listyindex = "1";
        wx.request({
            //url: 'http://localhost:8080/wxpay/wxpay/pay',
            url: 'https://wwl.ycws.cc/wxpay/wxpay/pay',
            data: {
                head: app.globalData.head,
                body: {
                    orderCode: orderCode,
                    openId: app.globalData.openId
                }
            },
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
            // header: {}, // 设置请求的 header
            success: function (res) {
                console.info(res.data)
                if (600 == res.data.head.resCode) {
                    //console.info(res.data.body)
                    //统一下单成功
                    wx.requestPayment({
                        timeStamp: res.data.body.timeStamp,
                        nonceStr: res.data.body.nonceStr,
                        package: res.data.body.packageStr,
                        signType: 'MD5',
                        paySign: res.data.body.sign,
                        success: function (res) {
                            console.log('支付成功');
                            wx.request({
                                url: 'https://wwl.ycws.cc/ssm/uploadfile/update',
                                data: {
                                    'yid': that.data.yid,
                                    'yname': that.data.yname,
                                    'ysex': that.data.ysex,
                                    'yowner': that.data.yowner,
                                    'yphone': that.data.yphone,
                                    'yaddress': that.data.yaddress,
                                    'createtime': that.data.createtime,
                                    'updatetime': that.data.updatetime,
                                    'ynumber': that.data.ynumber,
                                    'yindex': listyindex
                                },
                                method: 'POST',  //默认为 GET 有效值：OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
                                header: { 'content-type': 'application/x-www-form-urlencoded' },
                                success: function (res) {
                                    wx.redirectTo({
                                        url: '../../pages/newshowuser/newshowuser?ynumber=' + that.data.ynumber
                                    })
                                },
                                fail: function (res) {
                                    console.log("添加失败");
                                }
                            })
                        },
                        'fail': function (res) {
                        }
                    })
                }
                else if (11 == res.data.head.resCode) {
                    app.loginServer()
                    wx.showToast({
                        title: "请求支付服务器失败，请稍后再试",
                        icon: "FAIL",
                        duration: 1000
                    })
                } else {
                    var msg
                    if (res.data.body != null) {
                        msg = res.data.body
                    }
                    else {
                        msg = "支付请求失败，请稍后再试"
                    }
                    wx.showToast({
                        title: msg,
                        icon: "FAIL",
                        duration: 1000
                    })
                    //that.switchToOrder()
                }
            },
            fail: function () {
                wx.showToast({
                    title: "请求支付服务器失败，请稍后再试",
                    icon: "FAIL",
                    duration: 1000
                })
                that.switchToOrder()
            }
        })
    }
})